Skip to content

feat(bootstrapper): record bootstrap stack state on each loop iteration#1159

Open
dhellmann wants to merge 2 commits into
python-wheel-build:mainfrom
dhellmann:worktree-bootstrap-stack-record
Open

feat(bootstrapper): record bootstrap stack state on each loop iteration#1159
dhellmann wants to merge 2 commits into
python-wheel-build:mainfrom
dhellmann:worktree-bootstrap-stack-record

Conversation

@dhellmann
Copy link
Copy Markdown
Member

Summary

Writes bootstrap-stack.json to the work directory before each iteration of the DFS loop in Bootstrapper.bootstrap(). The file is a JSON array where index 0 is the next item to be processed (stack[-1]), overwritten on each iteration. Each entry captures identity and accumulated state fields (req, req_type, phase, resolved_version, source_url, why, parent, dep sets); heavy build objects (build_env, paths, build_result) are intentionally excluded.

Enables debugging, progress inspection, and post-mortem analysis of interrupted runs.

🤖 Generated with Claude Code

@dhellmann dhellmann requested a review from a team as a code owner May 14, 2026 21:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 281b9a4e-6648-4a9f-a559-42034072a4fa

📥 Commits

Reviewing files that changed from the base of the PR and between 27e56a7 and 0abe106.

📒 Files selected for processing (2)
  • src/fromager/bootstrapper.py
  • tests/test_bootstrapper.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/test_bootstrapper.py
  • src/fromager/bootstrapper.py

📝 Walkthrough

Walkthrough

The PR adds persistent stack recording to the bootstrap resolver. Bootstrapper now sets a _stack_filename in the constructor, calls _record_stack_state(stack) at the start of each DFS iteration, and implements _record_stack_state to serialize pending WorkItems (fields: req/req_type/phase/resolved_version/source_url/build_sdist_only, why_snapshot, optional parent, sorted build-dep sets) and overwrite bootstrap-stack.json. Tests add fixtures and assertions validating serialization shape, deterministic dep-set ordering, file creation/overwrite semantics, pop-order preservation, and that bootstrap() calls the recorder.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding stack state recording to each bootstrap loop iteration.
Description check ✅ Passed The description clearly explains the feature, its implementation details, and purpose for debugging and analysis.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dhellmann dhellmann requested a review from rd4398 May 14, 2026 21:57
@mergify mergify Bot added the ci label May 14, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fromager/bootstrapper.py`:
- Around line 1305-1307: The current bootstrap() snapshot write using
open(self._stack_filename, "w") may truncate the file and abort bootstrap on
error; instead, serialize the reversed(stack) into records and write JSON
atomically by writing to a temporary file in the same directory (e.g., use
tempfile.NamedTemporaryFile or a .tmp path) and then atomically replace the
target with os.replace; catch and log any exceptions (use the existing logger on
the object, e.g., self._logger or fallback logger) as a non-fatal warning so
bootstrap() continues on failure, referencing the existing serialize() call and
self._stack_filename to locate the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 876da36e-8403-4513-abee-eb324d8b2989

📥 Commits

Reviewing files that changed from the base of the PR and between bd86c56 and 27e56a7.

📒 Files selected for processing (2)
  • src/fromager/bootstrapper.py
  • tests/test_bootstrapper.py

Comment thread src/fromager/bootstrapper.py
Comment thread src/fromager/bootstrapper.py

# Main iterative DFS loop
while stack:
self._record_stack_state(stack)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than directly calling it , should we call it from a try/exception block. The idea is to write exceptions that escape the loop. Because it would be efficient writing when required as compared to writing the entire stack as JSON to disk on every iteration of the DFS loop

try:
    while stack:
        item = stack.pop()
        self.why = list(item.why_snapshot)

        with req_ctxvar_context(item.req), self._track_why(item):
            try:
                new_items = self._dispatch_phase(item)
            except Exception as err:
                new_items = self._handle_phase_error(item, err)
        # ... rest of loop ...
except Exception:
    self._record_stack_state(stack)
    raise

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes a lot less time to write than you might think, and having it available as work is progressing gives you the option of watching what the tool is doing as it works.

dhellmann and others added 2 commits May 15, 2026 17:58
Write `bootstrap-stack.json` to the work directory before each iteration
of the DFS loop, capturing the full stack as a JSON array (index 0 =
next item to pop). Enables debugging, progress inspection, and
post-mortem analysis of interrupted runs.

Co-Authored-By: Claude <claude@anthropic.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Log the path of the bootstrap stack JSON file once when `Bootstrapper`
is initialized, so users know where to find it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
@dhellmann dhellmann force-pushed the worktree-bootstrap-stack-record branch from 27e56a7 to 0abe106 Compare May 15, 2026 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants